package org.yjc.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name="yjc_course")
public class Course {
	private Integer id; //id
	private String courseName; //课程名
	private String courseHour; //课时
	@JsonIgnore
	private List<Student> students=new ArrayList<>();
	@JsonIgnore
	private List<Grade> grades=new ArrayList<>();
	
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(length=10)
	public String getCourseName() {
		return courseName;
	}
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}
	@Column(length=20)
	public String getCourseHour() {
		return courseHour;
	}
	public void setCourseHour(String courseHour) {
		this.courseHour = courseHour;
	}
	@OneToMany(mappedBy="course")
	public List<Grade> getGrades() {
		return grades;
	}
	public void setGrades(List<Grade> grades) {
		this.grades = grades;
	}
	public Course(Integer id, String courseName, List<Student> students, List<Grade> grades) {
		super();
		this.id = id;
		this.courseName = courseName;
		this.students = students;
		this.grades = grades;
	}
	public Course() {
		super();
	}
	
	@Transient
	public List<Student> getStudents() {
		List<Student> students=new ArrayList<>();
		for (Grade grade : getGrades()) {
			students.add(grade.getStudent());
		}
		return students;
	}
}
